<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='./vue.global.js'></script>
</head>

<body>
    <div id='app'>
        <div id="dynamicexample">
            <h3>Scroll down inside this section ↓</h3>
            <p v-pin:[direction]="200">I am pinned onto the page at 200px to the left.</p>
        </div>
    </div>
    <script>
        const app = Vue.createApp({
            data() {
                return {
                    direction: 'bottom'
                }
            }
        })

        app.directive('pin', {
            mounted(el, binding) {
                el.style.position = 'fixed'
                // binding.arg 是我们传递给指令的参数
                const s = binding.arg || 'top'
                el.style[s] = binding.value + 'px'
            }
        })

        const vm = app.mount('#app')
    </script>
</body>

</html>